/**
 * Created by Ysssssss on 20/12/15.
 */
import { arr2Obj } from '../../../../common/utils';

module.exports = Behavior({
    properties: {
        checkedList: {
            type: Array,
            value: [],
        },
        showCheckboxButton: {
            type: Boolean,
            value: false
        },
    },
    methods: {
        onCheckboxChange(e) {
            const ids = e.detail;
            const { productList } = this.data;
            const productMap = arr2Obj(productList, 'productId');
            let products = ids.map(i => productMap[i]);
            products = products.filter(i => !!i);
            this.triggerEvent('handleProductChecked', { ids, products });
        },
    }
})
